/*
 * AnalogToDigitalConverter.hpp
 *
 * Copyright 2012 Pieter Agten
 *
 * This file is part of tltgen.
 *
 * tltgen is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * tltgen is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with tltgen.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @file   AnalogToDigitalConverter.hpp
 * @author Pieter Agten (pieter.agten@gmail.com)
 * @date   28 feb 2012
 */

#ifndef ANALOGTODIGITALCONVERTER_HPP
#define ANALOGTODIGITALCONVERTER_HPP

#include <boost/lexical_cast.hpp>
#include <boost/serialization/access.hpp>
#include <boost/serialization/version.hpp>

#include "Voltage.hpp"
#include "AdcValue.hpp"

#include "SerializationException.hpp"

using boost::lexical_cast;

namespace tltgen {

  class AdcVisitor;

  /**
   * The abstract AnalogToDigitalConverter class defines the interface that concrete analog to
   * digital converter models must adhere to.
   */
  class AnalogToDigitalConverter {
  public:
    virtual ~AnalogToDigitalConverter();

    /**
     * Returns whether a given ADC value is a valid output value for this ADC
     * model.
     *
     * @param  adcValue the ADC value to check
     * @return whether a given ADC value is a valid output value for this ADC
     *         model
     */
    virtual bool isValidOutputValue(AdcValue adcValue) const = 0;

    virtual Voltage getInputVoltage(AdcValue adcValue) const = 0;

    /**
     * Returns whether a given voltage is a valid input voltage for this ADC
     * model.
     *
     * @param  voltage the voltage to check
     * @return whether a given voltage is a valid input voltage for this ADC
     *         model
     */
    virtual bool isValidInputVoltage(Voltage voltage) const = 0;

    virtual AdcValue getOutputValue(Voltage inputVoltage) const = 0;

    /**
     * Returns the ADC's lowest output value.
     *
     * @return the ADC's lowest output value
     */
    virtual AdcValue getMinimumOutputValue(void) const = 0;

    /**
     * Returns the ADC's highest output value.
     *
     * @return the ADC's highest output value
     */
    virtual AdcValue getMaximumOutputValue(void) const = 0;

    virtual void accept(AdcVisitor* visitor) const = 0;

  private:
    friend class boost::serialization::access;
    template<class Archive> void serialize(Archive & ar, unsigned int version)
    {
      if (version != 0) {
        throw tltgen::SerializationException("Unknown version " + 
					     lexical_cast<std::string>(version) + " for AnalogToDigitalConverter.");
      }
    }
  };

}

BOOST_CLASS_VERSION(tltgen::AnalogToDigitalConverter, 0)

#endif
